import 'package:Flutter/custom_tab_bar_app.dart';
import 'package:Flutter/dotcon/page/channel_page.dart';
import 'package:Flutter/dotcon/page/home_page.dart';
import 'package:Flutter/dotcon/page/setting_page.dart';
import 'package:Flutter/dotcon/widgets/custom_color_select.dart';
import 'package:flutter/material.dart';

import '../frame_animation_image.dart';
import '../main_text.dart';

class BottomNavigationPage extends StatefulWidget {

  const BottomNavigationPage({Key? key});

  @override
  State<BottomNavigationPage> createState() => _BottomNavigationPageState();

}

class _BottomNavigationPageState extends State<BottomNavigationPage> with RestorationMixin {

  final RestorableInt _currentIndex = RestorableInt(1);
  var bottomNavigationBarItems = <ItemEntity>[
    ItemEntity(
      "images/find_default.png",
      ["images/find_select_1.png","images/find_select_2.png","images/find_select_3.png","images/find_select_4.png","images/find_select_5.png", "images/find_select_6.png",
        "images/find_select_7.png","images/find_select_8.png","images/find_select_9.png","images/find_select_10.png","images/find_select_11.png", "images/find_select_12.png",
        "images/find_select_13.png", "images/find_select_14.png","images/find_select_15.png","images/find_select_16.png","images/find_select_17.png","images/find_select_18.png",
        "images/find_select_19.png","images/find_select_20.png"],
      "发现",
      GlobalKey<FrameAnimationImageState>(),
      50
    ),
    ItemEntity(
      "images/mode_default.png",
      ["images/mode_select_1.png","images/mode_select_2.png","images/mode_select_3.png","images/mode_select_4.png","images/mode_select_5.png", "images/mode_select_6.png",
        "images/mode_select_7.png","images/mode_select_8.png","images/mode_select_9.png","images/mode_select_10.png","images/mode_select_11.png", "images/mode_select_12.png",
        "images/mode_select_13.png", "images/mode_select_14.png","images/mode_select_15.png","images/mode_select_16.png","images/mode_select_17.png","images/mode_select_18.png",
        "images/mode_select_19.png","images/mode_select_20.png"],
      "频道",
      GlobalKey<FrameAnimationImageState>(),
      50
    ),
    ItemEntity(
      "images/cloud_default.png",
      ["images/cloud_select_1.png","images/cloud_select_2.png","images/cloud_select_3.png","images/cloud_select_4.png","images/cloud_select_5.png", "images/cloud_select_6.png",
        "images/cloud_select_7.png","images/cloud_select_8.png","images/cloud_select_9.png","images/cloud_select_10.png","images/cloud_select_11.png", "images/cloud_select_12.png",
        "images/cloud_select_13.png",
        "images/cloud_select_14.png","images/cloud_select_15.png","images/cloud_select_16.png","images/cloud_select_17.png","images/cloud_select_18.png","images/cloud_select_19.png","images/cloud_select_20.png"],
      "云素材",
      GlobalKey<FrameAnimationImageState>(),
        50
    ),
    ItemEntity(
      "images/rhythm_default.png",
      ["images/rhythm_select_1.png","images/rhythm_select_2.png","images/rhythm_select_3.png","images/rhythm_select_4.png","images/rhythm_select_5.png", "images/rhythm_select_6.png",
        "images/rhythm_select_7.png","images/rhythm_select_8.png","images/rhythm_select_9.png","images/rhythm_select_10.png","images/rhythm_select_11.png", "images/rhythm_select_12.png", "images/rhythm_select_13.png",
        "images/rhythm_select_14.png","images/rhythm_select_15.png","images/rhythm_select_16.png","images/rhythm_select_17.png","images/rhythm_select_18.png","images/rhythm_select_19.png","images/rhythm_select_20.png",
        "images/rhythm_select_21.png","images/rhythm_select_22.png","images/rhythm_select_23.png","images/rhythm_select_24.png","images/rhythm_select_25.png","images/rhythm_select_26.png","images/rhythm_select_27.png",
        "images/rhythm_select_28.png"],
      "律动",
      GlobalKey<FrameAnimationImageState>(),
        40
    ),
    ItemEntity(
      "images/set_default.png",
      ["images/set_select_1.png","images/set_select_2.png","images/set_select_3.png","images/set_select_4.png","images/set_select_5.png", "images/set_select_6.png",
        "images/set_select_7.png","images/set_select_8.png","images/set_select_9.png","images/set_select_10.png","images/set_select_11.png", "images/set_select_12.png", "images/set_select_13.png",
        "images/set_select_14.png","images/set_select_15.png","images/set_select_16.png","images/set_select_17.png","images/set_select_18.png","images/set_select_19.png","images/set_select_20.png"],
      "设置",
      GlobalKey<FrameAnimationImageState>(),
        50
    ),
  ];
  var navigationItems = <Widget>[ HomePage(), ChannelPage(), ColorSelectPage(), MyApp(), SettingPage()];

  @override
  String get restorationId => "restorationId";

  @override
  void restoreState(RestorationBucket? oldBucket, bool initialRestore) {
    registerForRestoration(_currentIndex, 'bottom_navigation_tab_index');
  }

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    _currentIndex.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return
      Scaffold(
        body:
        Stack(
          children: [
            Image.asset(
              "images/find_bg.png",
              width: double.infinity,
              height: double.infinity,
              fit: BoxFit.cover,//会按图片的长宽比放大后居中填满显示空间，图片不会变形，超出显示空间部分会被剪裁
            ),
            navigationItems[_currentIndex.value],
          ],
        ),
        bottomNavigationBar: CustomBottomNavigationBar(
          items: bottomNavigationBarItems,
          currentIndex: _currentIndex.value,
          onTap: (index) {
            setState(() {
              _currentIndex.value = index;
            });
          },
        ),
      );
  }
}
